package com.bootdo.wx.service.impl;

import com.bootdo.wx.dao.CmsMaterialDao;
import com.bootdo.wx.domain.CmsMaterialDO;
import com.bootdo.wx.service.CmsMaterialService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class CmsMaterialServiceImpl implements CmsMaterialService {
	@Autowired
	private CmsMaterialDao cmsMaterialDao;
	
	@Override
	public CmsMaterialDO get(String id){
		return cmsMaterialDao.get(id);
	}
	
	@Override
	public List<CmsMaterialDO> list(Map<String, Object> map){
		return cmsMaterialDao.list(map);
	}

	@Override
	public PageInfo<CmsMaterialDO> queryAll(Map<String,Object> map) {
		int pageNumber =1;
		int pageSize =10;
		if (map.containsKey("pageNumber")){
			pageNumber = Integer.parseInt(map.get("pageNumber").toString());
		}
		if (map.containsKey("pageSize")){
			pageSize = Integer.parseInt(map.get("pageSize").toString());
		}
		pageNumber = pageNumber < 1 ? 1 : pageNumber;
		pageSize = pageSize < 1 ? 10 : pageSize;
		PageHelper.startPage(pageNumber, pageSize);
		List<CmsMaterialDO> list =cmsMaterialDao.queryAll();
		return null == list ? null : new PageInfo<CmsMaterialDO>(list);
//		return cmsMaterialDao.queryAll();
	}

	@Override
	public int count(Map<String, Object> map){
		return cmsMaterialDao.count(map);
	}
	
	@Override
	public int save(CmsMaterialDO cmsMaterial){
		return cmsMaterialDao.save(cmsMaterial);
	}
	
	@Override
	public int update(CmsMaterialDO cmsMaterial){
		return cmsMaterialDao.update(cmsMaterial);
	}
	
	@Override
	public int remove(String id){
		return cmsMaterialDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return cmsMaterialDao.batchRemove(ids);
	}
	
}
